#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
		//         0  1  2  3  4  5  6  7  8  9  10 11 12
	int m = 0; int n = 0; int i = 0;
	
	while (scanf("%d %d", &m, &n) == 2)
	{
		if ((m % 4 == 0) && (m % 100 != 0) || (m % 400 == 0))
		{
			arr[2]++;
		}
		int day = arr[n];
		printf("%d", day);
		printf("\n");
		arr[2] = 28;
	}

	return 0;
}